package com.shahe.GirlsDay.MyView;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import com.shahe.GirlsDay.R;

public class CycleChartView extends View {

    private Paint paint;

    public CycleChartView(Context context) {
        super(context);
        paint = new Paint();
        paint.setAntiAlias(true);
    }

    public void onDraw(Canvas canvas) {
        //canvas.drawColor(Color.WHITE);
        drawAxis(canvas);
        drawChart(canvas);
    }

    public void drawAxis(Canvas canvas) {
        paint.setColor(getResources().getColor(R.color.chartLine));
        paint.setStrokeWidth(8);
        canvas.drawLine(100, 600, 680, 600, paint);// 横线
        canvas.drawLine(100, 80, 100, 600, paint);// 竖线

        paint.setColor(getResources().getColor(R.color.chartDottedLine));
        paint.setStrokeWidth(4);
        canvas.drawLine(100, 500, 680, 500, paint);// 横虚线
        canvas.drawLine(100, 400, 680, 400, paint);// 横虚线
        canvas.drawLine(100, 300, 680, 300, paint);// 横虚线
        canvas.drawLine(100, 200, 680, 200, paint);// 横虚线
        canvas.drawLine(100, 100, 680, 100, paint);// 横虚线

        canvas.drawLine(200, 80, 200, 600, paint);// 竖虚线
        canvas.drawLine(300, 80, 300, 600, paint);// 竖虚线
        canvas.drawLine(400, 80, 400, 600, paint);// 竖虚线
        canvas.drawLine(500, 80, 500, 600, paint);
        canvas.drawLine(600, 80, 600, 600, paint);// 竖虚线

        int x = 190;
        int y = 610;

        paint.setTextSize(30);
        paint.setColor(Color.BLACK);
        for (int i = 0; i < 5; i++) {
            // 横线
            canvas.drawText(i + 1 + "", x, 640, paint);
            x += 100;
        }
        for (int i = 0; i < 6; i++) {
            // 竖线
            canvas.drawText(10 * (i + 0) + "", 40, y, paint);
            y -= 100;
        }

        canvas.drawText("Days",20,60,paint);
        canvas.drawText("Date",660,640,paint);

    }

    // 画曲线
    void drawChart(Canvas canvas) {
        paint.setColor(getResources().getColor(R.color.title_color));
        paint.setStrokeWidth(10);
        canvas.drawLine(100, 600, 200, 500, paint);// 横+50,竖-50；
        canvas.drawLine(200, 500, 300, 400, paint);
        canvas.drawLine(300, 400, 400, 500, paint);
        canvas.drawLine(400, 500, 500, 400, paint);
    }

}
